﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;

namespace POS_NEW

{
    public partial class frmTuNgayDenNgay : Form
    {
        public frmTuNgayDenNgay(string i)
        {
            InitializeComponent();
            loaiBC = i;
          
        }
        string loaiBC;
        private void btnEnter_Click(object sender, EventArgs e)
        {
            if (dtTuNgay.Value == null || dtDenNgay.Value == null || dtTuNgay.DateTime > dtDenNgay.DateTime)
                return;
            if (loaiBC == "BCXNT")
            {
                DataTable dt = AccessDataLayer.ExecuteDT("spBaocao_XuatNhapTon", CommandType.StoredProcedure
                    , "@TuNgay", dtTuNgay.Value, "@DenNgay", dtDenNgay.Value,"@ID_ChiNhanh",myProgress.ID_ChiNhanh);
                POS_NEW.report.rptBaoCao_XuatNhapTon rpt = new report.rptBaoCao_XuatNhapTon();
                //ReportDocument rpt = new ReportDocument();
                //rpt.Load(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("bin")) + @"\report\rptBaoCao_XuatNhapTon.rpt");
                rpt.DataDefinition.FormulaFields["TuNgay"].Text = "'"+dtTuNgay.Value+"'";
                rpt.DataDefinition.FormulaFields["DenNgay"].Text = "'" + dtDenNgay.Value + "'";
                rpt.SetDataSource(dt);
                myProgress.SubReportHeader(rpt);
                using (frmDisplayReport frm = new frmDisplayReport(rpt))
                {
                    if (frm.ShowDialog() == DialogResult.Cancel)
                        rpt.Dispose();
                }
            }
            else
                if (loaiBC == "BCXNT_INGIA")
            {
                DataTable dt = AccessDataLayer.ExecuteDT("spBaocao_XuatNhapTon", CommandType.StoredProcedure
                    , "@TuNgay", dtTuNgay.Value, "@DenNgay", dtDenNgay.Value, "@ID_ChiNhanh", myProgress.ID_ChiNhanh);
                POS_NEW.report.rptBaoCao_XuatNhapTon_InGia rpt = new report.rptBaoCao_XuatNhapTon_InGia();
                //ReportDocument rpt = new ReportDocument();
                //rpt.Load(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("bin")) + @"\report\rptBaoCao_XuatNhapTon_InGia.rpt");
                rpt.DataDefinition.FormulaFields["TuNgay"].Text = "'" + dtTuNgay.Value + "'";
                rpt.DataDefinition.FormulaFields["DenNgay"].Text = "'" + dtDenNgay.Value + "'";
                rpt.SetDataSource(dt);
                myProgress.SubReportHeader(rpt);
                using (frmDisplayReport frm = new frmDisplayReport(rpt))
                {
                    if (frm.ShowDialog() == DialogResult.Cancel)
                        rpt.Dispose();
                }
            }
               
        }

        private void dtTuNgay_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode==Keys.Enter)
            dtDenNgay.Focus();
        }

        private void dtDenNgay_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            btnEnter.Focus();
        }

        private void dtTuNgay_Enter(object sender, EventArgs e)
        {
            dtTuNgay.SelectAll();
        }

        private void dtDenNgay_Enter(object sender, EventArgs e)
        {
            dtDenNgay.SelectAll();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmTuNgayDenNgay_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
                btnThoat_Click(null, null);
        }

        private void frmTuNgayDenNgay_Load(object sender, EventArgs e)
        {

        }

    }
}
